home *** CD-ROM | disk | FTP | other *** search
- Path: news.connectnet.com!usenet
- From: Brain <provstu@cts.com>
- Newsgroups: comp.lang.c,comp.unix.questions,comp.unix.programmer
- Subject: Re: beginner needs your help ASAP
- Date: Fri, 05 Apr 1996 10:55:02 -0800
- Organization: Providenc Communications
- Message-ID: <31656C86.2EDF@cts.com>
- References: <4in3s5$a7a@risky.ecs.umass.edu> <4j7fod$2de@tui.pinnacle.co.nz>
- NNTP-Posting-Host: max-nc-163.connectnet.com
- Mime-Version: 1.0
- Content-Type: multipart/mixed; boundary="------------746B70537F"
- X-Mailer: Mozilla 2.01 (Win16; I)
-
- This is a multi-part message in MIME format.
-
- --------------746B70537F
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
-
- Jonathan Chen wrote:
- >
- > In <4in3s5$a7a@risky.ecs.umass.edu> sebag@ecs.umass.edu writes:
- >
- > >I am a new C programmer who would like to do some basic graphics.
- > >I am using a UNIX machine and I am logging on through telnet.
- > >I would like to clear the screen, and write characters at different
- > >places on the screen. If I used printf, it would print on the next
- > >line. I am trying to choose where on the screen the characters go.
- > >Is this easy to do?
- >
- > man curses(3)
- > --
- > +--
- > | Jonathan Chen <jonc@pinnacle.co.nz> |
- > --+Here attatched is some code!
-
- Brain<provstu@cts.com>
-
- --------------746B70537F
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- Content-Disposition: inline; filename="LOGO.C"
-
- //INCLUDE/////////////////////
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <dos.h>
- #include <string.h>
- #include <graph4.h>
- #include <graph31.h>
- #include <conio.h>
- #include <unixio.h>
- #include <math.h>
-
- //GLOBALS/////////////////////
-
-
-
- //PROTOTYPES//////////////////
-
- void pcxi(pcx_picture_ptr image);
-
- void pcxl(char *filename, pcx_picture_ptr image, int enable_palette);
-
- void pcxb(pcx_picture_ptr image);
-
- void pcxd(pcx_picture_ptr image);
-
- void setpr(int index, RGB_color_ptr color);
-
- void setvm(int mode);
-
- //FUNCTIONS//////////////////
-
- void pcxi(pcx_picture_ptr image)
- {
- //Allocates a set of memory for a picture.
-
- if(!(image -> buffer = (char *) malloc(SCREEN_WIDTH * SCREEN_HEIGHT + 1)))
- printf("\a\a\aOut of memory!");
-
-
- }
- ///////////////////////////
- void pcxl(char *filename, pcx_picture_ptr image, int enable_palette)
- {
- //This loads a PCX file(& header) into a memory buffer,and decompresses in a
- //second buffer.
-
- FILE *fp ;
-
- int num_bytes, index;
- long count ;
- unsigned int data ;
- char far *temp_buffer ;
-
- //Open up that file!
-
- fp = fopen(filename, "rb");
-
- //Load the header.
-
- temp_buffer = (char far *)image ;
-
- for(index = 0; index < 128; index++)
- {
- temp_buffer[index] = (char)getc(fp) ;
- }
-
- //Load the data and decompress.
-
- count = 0 ;
-
- while(count <= SCREEN_WIDTH * SCREEN_HEIGHT)
- {
- //Get the first piece of the data.
-
- data = (unsigned int)getc(fp) ;
-
- //Hey, are we in Run Length Encoding?(RLE)
-
- if(data >= 192 && data <= 255)
- {
- //It is, so how many bytes are in the RLE?
-
- num_bytes = data - 192 ;
-
- //Get the REAL data for the RLE.
-
- data = (unsigned char)getc(fp) ;
-
- //Reproduce the data in the buffer by the number of bytes(num_bytes).
-
- while(num_bytes --> 0)
- {
- image -> buffer[count++] = data ;
-
- }
-
- }
- else
- {
- //We don't have any RLE compression!
-
- image -> buffer[count++] = data ;
-
- }
-
- }
-
- //Move to the end of the file(or EOF), then back up to the beginning of the palette.
-
- fseek(fp, -768L, 2) ;
-
- //Load the palette into the palette reigsters.
-
- for(index = 0; index < 256; index++)
- {
- //Get the Red out!
-
- image -> palette[index].red = (unsigned char)(getc(fp) >> 2) ;
-
- //Get the Green out!
-
- image -> palette[index].green = (unsigned char)(getc(fp) >> 2) ;
-
- //Get the Blue out!
-
- image -> palette[index].blue = (unsigned cha)(getc(fp) >> 2);
-
- }//Now we have the RGB!
-
- fclose(fp) ;
-
- //Enable the loaded palette if instructed to.
-
- if(enable_palette)
- {
- //For each register , set to the new color values.
-
- for(index = 0; index < 256; index++)
- {
- setpr(index, (RGB_color_ptr)&image -> palette[index]) ;
-
- }
- }
- }
- //////////////////////////////////
- void pcxb(pcx_picture_ptr image)
- {
- //Copy the file into Video memory.
-
- char far *data;
- data = image -> buffer;
- (unsigned char far *)video_buffer = (unsigned char far *)0xA000000L ;
-
-
- #asm
- push ds ;save the data
- les di, video_buffer ;point es:di to video buffer
- lds si, data ;point ds:si to the data
- mov cx,320*200/2 ;move 3200 words
- cld ;set directon to forward
- rep movsw ;do the string operation
- pop ds ;restore the data
-
-
-
- #endasm
- }
- //////////////////////////////////
- void setpr(int index, RGB_color_ptr color)
- {
- //This function sets a single volor look-up table value indexed with the value int the color structure.
-
- //Tell the VGA(Video Graphics Adapter) card we're going to update a palette register.
-
- outp(PALETTE_MASK, 0xff) ;
-
- //Tell the VGA card which register we'll be updating.
-
- outp(PALETTE_REGISTER_WR, index) ;
-
- //Now update each of the RGB colors.
-
- outp(PALETTE_DATA, color -> red) ;
- outp(PALETTE_DATA, color -> green) ;
- outp(PALETTE_DATA, color -> blue) ;
-
- }
- void setvm(int mode)
- {
- union REGS inregs,outregs ;
-
- inregs.h.ah = 0 ;
-
- inregs.h.al = (unsigned char) mode ;
-
- int86(0x10, &inregs, &outregs);
-
- }
- /////////////////////////////////////
- main()
- {
- }
-
- --------------746B70537F--
-
-